package com.felix.interview;

import lombok.*;

/**
 * FinallyDemo
 *
 * @author xjh
 * @version 1.0
 * @date 2019-02-20
 */
public class FinallyDemo {

    private static Cat tom = new Cat();
    private static Integer i = 1225;
    private static String str = "abc";

    public static void main(String[] args) {
        Dog laifu = new Dog("laifu");
        Dog wangcai = new Dog("wangcai");
        System.out.println(laifu.equals(wangcai));
        System.out.println(laifu.hashCode());
        System.out.println(wangcai.hashCode());
    }

    public static Cat method() {
        try {
            tom.name = "tom";
            tom.age = 1;
            return tom;
        } finally {
            tom.name = "tim";
            tom.age = 2;
        }
    }

    public static Integer method1() {
        try {
            return i;
        } finally {
            i = 2222;
        }
    }

    public static String method2() {
        try {
            str += " good";
            return str;
        } finally {
            str = "gbc";
        }
    }
}

@Data
class Cat {
    String name;
    Integer age;
}

@Setter
@Getter
@ToString
@AllArgsConstructor
class Dog {
    private String name;

    @Override
    public int hashCode() {
        return name.indexOf('i');
    }

    @Override
    public boolean equals(Object obj) {
        return true;
    }
}